﻿Public Class Proxy


    Private duration As New System.TimeSpan(0)
    Public Property LastCallDuration() As System.TimeSpan
        Get
            Return duration
        End Get
        Set(ByVal value As System.TimeSpan)
            duration = value
        End Set
    End Property

    Public Function SendRequest(ByVal Request As Common.Request) As Common.Response

        Dim sendStr As String

        Dim json As New System.Web.Script.Serialization.JavaScriptSerializer()
        sendStr = json.Serialize(Request)

        Console.WriteLine("REQUEST:" + sendStr)

        Dim wc As New System.Net.WebClient()
        wc.Headers.Add("Content-Type", "application/json; charset=utf-8")

        Dim dt As DateTime = DateTime.Now

        Dim response = wc.UploadString(Request.Connection.Server.ServerUri, sendStr)

        LastCallDuration = New TimeSpan(DateTime.Now.Ticks - dt.Ticks)


        Console.WriteLine("RESPONSE:" + response)

        Return json.Deserialize(Of Common.Response)(response)

    End Function
End Class
